const xlsx = require('xlsx')
const fs = require('fs')
const path = require('path')
const _ = require('lodash')

/** 读取数据 */
async function transformExl(date, file) {
  let workbook = xlsx.readFile(file.path) //workbook就是xls文档对象
  let sheetNames = workbook.SheetNames //获取表明
  let sheet = workbook.Sheets[sheetNames[0]] //通过表明得到表对象
  var data = xlsx.utils.sheet_to_json(sheet) //通过工具将表对象的数据读出来并转成json
  let name = []
  for (const key in data) {
    if (data[key]['操作人员+微信号'] !== undefined) {
      let cz = data[key]['操作人员+微信号']
      let deptname = data[key]['店铺名']
      let count = data[key][date]
      czry = _.split(cz, '+', 1)[0]
      name.push({ deptName: deptname, userName: czry, deptCount: count })
    }
  }
  return name
}

module.exports = transformExl
